package com.duniptech.soa.adapter;

import java.util.Collection;

public class CoupledMicroSim extends com.duniptech.kernel.modeling.AtomicImpl implements com.duniptech.kernel.modeling.api.Atomic {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private com.duniptech.kernel.simulation.CoordinatorImpl coordinator;
	
	public CoupledMicroSim(com.duniptech.kernel.modeling.api.Coupled model) {
		super(model.getName() + "AsAtomic");
		
		Collection<com.duniptech.kernel.modeling.api.Coupling> eic = model.getEICs();
		for(com.duniptech.kernel.modeling.api.Coupling c : eic) {
			this.addInport(c.getNamePortFrom());
		}
		Collection<com.duniptech.kernel.modeling.api.Coupling> eoc = model.getEOCs();
		for(com.duniptech.kernel.modeling.api.Coupling c : eoc) {
			this.addOutport(c.getNamePortTo());
		}
		
		coordinator = new com.duniptech.kernel.simulation.CoordinatorImpl(model);
	}
	
	public void deltext(double e, com.duniptech.kernel.modeling.api.Message x) {
		coordinator.injectInput(e, x);
	}


	public void deltint() {
		coordinator.deltfcn(coordinator.getTN());
	}

	public com.duniptech.kernel.modeling.api.Message lambda() {
		coordinator.lambda(coordinator.getTN());
		return coordinator.getOutput();
	}
	
	public double ta() {
		return coordinator.getTN() - coordinator.getTL(); 
	}

}
